/***
  Copyright (c) 2012 CommonsWare, LLC
  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy
  of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
  by applicable law or agreed to in writing, software distributed under the
  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  OF ANY KIND, either express or implied. See the License for the specific
  language governing permissions and limitations under the License.
  
  From _The Busy Coder's Guide to Android Development_
    http://commonsware.com/Android
*/

package com.gvitz.transaction.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.gvitz.transaction.utils.Config;

class DatabaseHelper extends SQLiteOpenHelper {
 
	
    private static final String DATABASE_NAME="gvitz.db";
	private static final int DATABASE_VERSION = 1;

  public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  

@Override
public void onCreate(SQLiteDatabase db) {

	 db.execSQL("CREATE TABLE IF NOT EXISTS "+ Config.tabla_transacciones +"(" 
			   + Config.trans_id + " INTEGER PRIMARY KEY, "
			   + Config.trans_monto + " TEXT,"   
			   + Config.trans_id_cliente + " TEXT," 
			   + Config.trans_nombre + " TEXT,"
			   + Config.trans_fecha + " TEXT,"
			   + Config.trans_id_tarjeta + " TEXT);");
	 
	 db.execSQL("CREATE TABLE IF NOT EXISTS "+ Config.tabla_tarjetas +"(" 
			   + Config.card_id + " INTEGER PRIMARY KEY, "
			   + Config.card_nombre + " TEXT,"  
			   + Config.card_type + " TEXT,"   
			   + Config.card_number + " TEXT);");
	 
	 
	 db.execSQL("CREATE TABLE IF NOT EXISTS "+ Config.tabla_clientes +"(" 
			   + Config.cliente_id + " INTEGER PRIMARY KEY, "
			   + Config.cliente_nombre + " TEXT,"   
			   + Config.cliente_direccion + " TEXT," 
			   + Config.cliente_latitud + " TEXT," 	              
			   + Config.cliente_longitud + " TEXT);");
  
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + Config.tabla_clientes );
    db.execSQL("DROP TABLE IF EXISTS " + Config.tabla_tarjetas );
    db.execSQL("DROP TABLE IF EXISTS " + Config.tabla_transacciones );
    onCreate(db);
	
}
}